package com.gxa.controller.wgl.customer;


import com.gxa.common.R;
import com.gxa.entity.SysQuestionManagement;
import com.gxa.service.CustomerQuestionService;
import com.gxa.utils.HeaderUtils;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


@Controller
@RequestMapping(value = "/customer/questionManagement")
@RequiresRoles(value = {"超级管理员","院长","主任","秘书"},logical = Logical.OR)
@Api(value = "客服问题管理",tags = "客服问题管理")
public class CustomerQuestionController {

    @Autowired
    CustomerQuestionService customerQuestionService;


    /**
     * 查询所有提问消息
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/findQuestionList",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有客服提问消息",notes = "查询所有客服提问消息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R findQuestionList(Integer currentPage,Integer pageSize){

        R r = customerQuestionService.getQuestionList(currentPage,pageSize);

        return r;
    }

    /**
     * 添加一条提问消息
     * @param question 消息实体
     * @return
     */
    @RequestMapping(value = "/addQuestion",method = RequestMethod.POST)
    @ApiOperation(value = "添加一条客服提问消息",notes = "添加一条客服提问消息",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R addQuestion(@RequestBody @ApiParam(name = "question",value = "消息实体",required = true) SysQuestionManagement question,
                         HttpServletRequest request){
        Integer userId = HeaderUtils.getUserID(request);
        question.setUserId(userId);

       return customerQuestionService.addQuestion(question);
    }

    /**
     * 修改一条提问消息
     * @param question 消息实体
     * @return
     */
    @RequestMapping(value = "/updateQuestion",method = RequestMethod.POST)
    @ApiOperation(value = "修改一条客服提问消息",notes = "修改一条客服提问消息",httpMethod = "POST", response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R updateQuestion(@RequestBody @ApiParam(name = "question",value = "消息实体",required = true) SysQuestionManagement question){
       return customerQuestionService.updateQuestionManagement(question);
    }

    /**
     * 通过条件查询提问消息
     * @param title 条件
     * @return
     */
    @RequestMapping(value = "/getQuestionByTitle",method = RequestMethod.GET)
    @ApiOperation(value = "条件查询所有客服消息",notes = "条件查询所有客服消息",httpMethod = "GET", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数默认第一页",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页显示记录数",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "title",value = "条件",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R getQuestionByTitle(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize")Integer pageSize ,@RequestParam("title") String title){
        return customerQuestionService.getQuestionListByTitle(currentPage, pageSize,title);
    }

    /**
     * 删除一条提问消息
     * @param id 问题id
     * @return
     */
    @RequestMapping(value = "/deleteQuestion",method = RequestMethod.POST)
    @ApiOperation(value = "删除一条问题消息",notes = "删除一条问题消息",httpMethod = "POST", response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "问题编号",paramType = "query",dataType = "String",required = true),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="登录成功"),
            @ApiResponse(code=400,message="代表参数格式不对"),
            @ApiResponse(code=404,message="代表找不到此请求"),
            @ApiResponse(code=500,message="代表后端代码出现异常"),
    })
    @ResponseBody
    public R deleteQuestion(@RequestParam("id")Integer id){
       return customerQuestionService.delQuestion(id);
    }

}
